<?php

/**
 * evenement form.
 *
 * @package    gesp
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class evenementForm extends BaseevenementForm {
	public function configure() {
		$this->setWidget('evt_prj_id', new sfWidgetFormInputHidden());
		$q = Doctrine_Query::Create()
			->from('categorie')
			->where('cat_prj_id = ?', $this->getObject()->getEvtPrjId());
		$this->setWidget(
			'evt_cat_id', 
			new sfWidgetFormDoctrineChoice(array(
				'model' => $this->getRelatedModelName('categorie'), 
				'query' => $q, 
				'order_by' => array('cat_categorie', 'asc'), 
				'add_empty' => '-- select --',
			))
		);

		// affectation auto de la date, modifiable
		$this->setWidget('evt_date', new DatePickerWidget(array('default' => date('d/m/Y'))));
		
		// redéfinition des validateurs
		$this->setValidator(
			'evt_prj_id',
			new sfValidatorDoctrineChoice(
				array('model' => $this->getRelatedModelName('projet'))
			)
		);
		$this->setValidator(
			'evt_date',
			new ValidatorDate(array(
				'required' => true,
				'date_format' => '/^(?P<day>\d+)\/(?P<month>\d+)(\/(?P<year>\d+))?/',
			))
		);

		// modification des libellés
		$this->widgetSchema->setLabels(array(
			'evt_date' => 'Date',
			'evt_cat_id' => 'Catégorie',
			'evt_evenement' => 'Evénement',
		));
	}
}
